export default {
  methods:{
    isOsSupport(os, deviceModel, funCode){
      if(os) {
        os = os.toUpperCase()
      }
      if('ANDROID' === os) {
        return true
      } else if('LINUX' === os) {
        // if('SP630' === deviceModel){
        //   return false
        // }
        if('remote_tab0' === funCode){
          return true
        } else if('remote_tab1' === funCode){
          return true
        } else if('remote_tab3' === funCode){
          return true
        } else if('collect_app_info' === funCode) {
          return true
        } else if('lock_terminal' === funCode) {
          return true
        } else if('unlock_terminal' === funCode) {
          return true
        } else if('app_operation' === funCode) {
          return true
        } else if('sim_card_sn' === funCode) {
          return true
        } else if('last_boot_time' === funCode) {
          return true
        } else if('offline_password' === funCode) {
          return true
        }
        return false
      } else if('RTOS' === os) {
        if('event' === funCode){
          return true
        }
        return false
      }
      return false
    },
    isFunctionSupport(funCode, modelCode, deviceFlag, otaVersion) {
      if(!funCode || !modelCode){
        return false
      }
      funCode = funCode.toUpperCase()
      modelCode = modelCode.toUpperCase()
      if(deviceFlag){
        deviceFlag = deviceFlag.toUpperCase()
      } else {
        deviceFlag = ''
      }
      if(otaVersion){
        otaVersion = otaVersion.toUpperCase()
      } else {
        otaVersion = ''
      }
      if(otaVersion.startsWith('V') || otaVersion.startsWith('D') || otaVersion.startsWith('T')){
        otaVersion = otaVersion.substring(1);
      }
      const userInfo = JSON.parse(
        localStorage.getItem(this.$store.getters.keys.storage.username)
      )
      const oid = userInfo ? userInfo.oid : ''
      if(funCode === 'KIOSK_MODEL') {
        if (modelCode === 'N950 PRO') {
          if (deviceFlag === 'A12') {
            if (otaVersion < '1.0.02') {
              return false
            }
          }
        } else if (modelCode === 'N950') {
          if (deviceFlag === 'A10') {
            if (otaVersion < '1.1.03') {
              return false
            }
          } else if(deviceFlag === 'A105G') {
            if (otaVersion < '1.1.04') {
              return false
            }
          }
        } else if (modelCode === 'N910 PLUS') {
          if (deviceFlag === 'A10') {
            if (otaVersion < '1.1.05') {
              return false
            }
          } else if(deviceFlag === 'A105G') {
            if (otaVersion < '1.1.05') {
              return false
            }
          }
        } else if (modelCode === 'N910') {
          if (deviceFlag === 'A10') {
            if (otaVersion < '1.1.05') {
              return false
            }
          } else if(deviceFlag === 'A105G') {
            if (otaVersion < '1.1.05') {
              return false
            }
          } else if (deviceFlag === 'A7') {
            if (otaVersion < '1.0.31') {
              return false
            }
          } else if (deviceFlag === 'SA2') {
            return false
          }
        } else if (modelCode === 'N910 PRO') {
          if (deviceFlag === 'A10') {
            if (otaVersion < '1.1.25') {
              return false
            }
          } else if(deviceFlag === 'A105G') {
            if (otaVersion < '1.1.25') {
              return false
            }
          }
        } else if (modelCode === 'N850') {
          if (deviceFlag === 'A7') {
            if (otaVersion < '1.0.16') {
              return false
            }
          } else if (deviceFlag === 'SA2') {
            return false
          }
        } else if (modelCode === 'N700') {
          if (deviceFlag === 'A7') {
            if (otaVersion < '1.0.17') {
              return false
            }
          } else if (deviceFlag === 'SA2') {
            return false
          }
        } else if (modelCode === 'CPOS X5') {
          if (deviceFlag === 'A10') {
            if (otaVersion < '1.1.01') {
              return false
            }
          } else {
            return false
          }
        } else if(modelCode === 'X800') {
          if (deviceFlag === 'A10') {
            if (otaVersion < '1.0.03') {
              return false
            }
          }
        }
      }
      else if(funCode === 'SET_LANG') {
        if (modelCode === 'N910') {
          if (deviceFlag === 'SA2') {
            return false
          }
        } else if (modelCode === 'N850') {
          return false
        } else if (modelCode === 'N700') {
          return false
        }
      }
      else if(funCode === 'SET_TIMEZONE') {
        if(modelCode === 'N950 PRO'){
          if(deviceFlag === 'A12'){
            if(otaVersion < '1.0.02'){
              return false
            }
          }
        } else if(modelCode === 'X800'){
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.0.03'){
              return false
            }
          }
        } else if(modelCode === 'N910'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.28'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N910 PRO'){
          if(otaVersion < '1.1.06'){
            return false
          }
        } else if(modelCode === 'N850'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.08'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N700'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.10'){
              return false
            }
          }else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'CPOS X5'){
          if(deviceFlag === 'A7') {
            if (otaVersion < '1.0.69') {
              return false
            }
          } else if(deviceFlag === 'A10') {
            if (otaVersion < '1.1.01') {
              return false
            }
          }
        } else if (modelCode === 'P300') {
          if (otaVersion < '1.1.01') {
            return false
          }
        }
      } else if(funCode === 'PAYMENT_MODULE_SETTING') {
        if(modelCode === 'N950 PRO'){
          if(deviceFlag === 'A12'){
            if(otaVersion < '1.0.02'){
              return false
            }
          }
        } else if(modelCode === 'X800'){
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.0.03'){
              return false
            }
          }
        } else if(modelCode === 'N910'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.28'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N910 PRO'){
          if(otaVersion < '1.1.12'){
            return false
          }
        } else if(modelCode === 'N850'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.07'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N700'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.10'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'CPOS X5'){
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.1.02'){
              return false
            }
          } else  if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.65'){
              return false
            }
          }
        }
      }
      else if(funCode === 'FLY_DESK') {
        if(modelCode === 'N950 PRO'){
          if(deviceFlag === 'A12'){
            if(otaVersion < '1.0.02'){
              return false
            }
          }
        } else if(modelCode === 'X800'){
          if('C72CE47B02C3A6269500D72E231BB69EEF4C5CD0EAEB42A6322B963284FA61B5' === oid) {
            return true
          }
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.0.03'){
              return false
            }
          }
        } else if(modelCode === 'N910'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.27'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N910 PRO'){
          if(otaVersion < '1.1.11'){
            return false
          }
        } else if(modelCode === 'N850'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.06'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N700'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.07'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'CPOS X5'){
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.1.01'){
              return false
            }
          } else if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.60'){
              return false
            }
          }
        }
      }
      else if(funCode === 'APPSTORE') {
        if(modelCode === 'N950 PRO'){
          if(deviceFlag === 'A12'){
            if(otaVersion < '1.0.02'){
              return false
            }
          }
        } else if(modelCode === 'X800'){
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.0.03'){
              return false
            }
          }
        } else if(modelCode === 'N910'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.27'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N910 PRO'){
          if(otaVersion < '1.1.11'){
            return false
          }
        } else if(modelCode === 'N850'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.06'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N700'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.07'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'CPOS X5'){
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.1.02'){
              return false
            }
          } else if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.60'){
              return false
            }
          }
        }
      }
      else if(funCode === 'FLY_KEY') {
        if(modelCode === 'N950 PRO'){
          if(deviceFlag === 'A12'){
            if(otaVersion < '1.0.02'){
              return false
            }
          }
        } else if(modelCode === 'X800'){
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.0.03'){
              return false
            }
          }
        } else if(modelCode === 'N910'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.28'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N910 PRO'){
          if(otaVersion < '1.1.14'){
            return false
          }
        } else if(modelCode === 'N850'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.08'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N700'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.10'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'CPOS X5'){
          return false
        }
      }
      else if(funCode === 'UNINSTALL_SETTING_APP') {
        if(modelCode === 'N950 PRO'){
          if(deviceFlag === 'A12'){
            if(otaVersion < '1.0.02'){
              return false
            }
          }
        } else if(modelCode === 'X800'){
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.0.03'){
              return false
            }
          }
        } else if(modelCode === 'N910'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.27'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N910 PRO'){
          if(otaVersion < '1.1.11'){
            return false
          }
        } else if(modelCode === 'N850'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.06'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'N700'){
          if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.07'){
              return false
            }
          } else if(deviceFlag === 'SA2'){
            return false
          }
        } else if(modelCode === 'CPOS X5'){
          if(deviceFlag === 'A10'){
            if(otaVersion < '1.1.01'){
              return false
            }
          } else if(deviceFlag === 'A7'){
            if(otaVersion < '1.0.69'){
              return false
            }
          }
        }
      }
      return true
    },
    /**
     * 对比两个版本的大小
     * @param version1
     * @param version2
     */
    versionCompare(version1, version2) {
      if(!version1 && !version2) {
        return 0
      } else if(version1 && !version2)  {
        return 1
      } else if(!version1 && version2) {
        return -1
      } else {
        let arr1 = version1.split(".")
        let arr2 = version2.split(".")
        let len1 = arr1.length
        let len2 = arr2.length
        let len = len1
        if(len2 <= len1) {
          len = len2
        }
        for(let i = 0; i< len; i++) {
          if (this.isNumber(arr1[i]) && this.isNumber(arr2[i])) {
            let number1 = Number(arr1[i])
            let number2 = Number(arr2[i])
            if(number1 > number2) {
              return 1
            } else if (number1 == number2) {
              if (i == len - 1) {
                if (len1 > len2) {
                  return 1
                } else if (len1 == len2) {
                  return 0
                } else if (len1 < len2) {
                  return -1
                }
              } else {
                continue
              }
            } else if (number1 < number2) {
              return -1
            }
          } else {
            if(arr1[i] > arr2[i]) {
              return 1
            } else if (arr1[i] == arr2[i]) {
              if (i == len - 1) {
                if (len1 > len2) {
                  return 1
                } else if (len1 == len2) {
                  return 0
                } else if (len1 < len2) {
                  return -1
                }
              } else {
                continue
              }
            } else if (arr1[i] < arr2[i]) {
              return -1
            }
          }
        }
      }
    },
    isNumber(value) {
      console.log(value, !isNaN(value))
      if(!isNaN(value)) {
        return true
      }
      return false
    }
  }
}
